package com.dyrs.delaytaskservice.nacos;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.naming.NamingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

@Controller
@RequestMapping("discovery")
public class DiscoveryController {

//    @NacosInjected
//    private NamingService namingService;

    @Autowired
    private RestTemplate restTemplate;

//    @RequestMapping(value = "/get", method = GET)
//    @ResponseBody
//    public List<Instance> get(@RequestParam String serviceName) throws NacosException {
//        return namingService.getAllInstances(serviceName);
//    }

    @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
    @ResponseBody
    public String echo(@PathVariable String str) {
        return restTemplate.getForObject("http://demo2/echo/" + str, String.class);
    }

}
